package com.gs.gaosheng.controller;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsImgs;
import com.gs.gaosheng.service.GsImgsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品图Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/imgs")
public class GsImgsController extends BaseController
{
    @Autowired
    private GsImgsService gsImgsService;

    /**
     * 查询商品图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsImgs gsImgs)
    {
        startPage();
        List<GsImgs> list = gsImgsService.selectGsImgsList(gsImgs);
        return getDataTable(list);
    }

    /**
     * 导出商品图列表
     */
    @Log(title = "商品图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsImgs gsImgs)
    {
        List<GsImgs> list = gsImgsService.selectGsImgsList(gsImgs);
        ExcelUtil<GsImgs> util = new ExcelUtil<GsImgs>(GsImgs.class);
        return util.exportExcel(list, "imgs");
    }

    /**
     * 获取商品图详细信息
     */
    @GetMapping(value = "/{imgId}")
    public AjaxResult getInfo(@PathVariable("imgId") Long imgId)
    {
        return AjaxResult.success(gsImgsService.selectGsImgsById(imgId));
    }

    /**
     * 新增商品图
     */
    @Log(title = "商品图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsImgs gsImgs)
    {
        return toAjax(gsImgsService.insertGsImgs(gsImgs));
    }

    /**
     * 修改商品图
     */
    @Log(title = "商品图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsImgs gsImgs)
    {
        return toAjax(gsImgsService.updateGsImgs(gsImgs));
    }

    /**
     * 删除商品图
     */
    @Log(title = "商品图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imgIds}")
    public AjaxResult remove(@PathVariable Long[] imgIds)
    {
        return toAjax(gsImgsService.deleteGsImgsByIds(imgIds));
    }
}
